//
//  NRWBaseViewController.m
//  NRWMall
//
//  Created by 邢毅 on 2018/5/7.
//  Copyright © 2018年 com.anpxd. All rights reserved.
//

#import "NRWBaseViewController.h"

@interface NRWBaseViewController ()<UIGestureRecognizerDelegate>

@end

@implementation NRWBaseViewController
{
@private
	NSTimeInterval _startTime;
}

#pragma mark - lifeCycle
- (void)viewDidLoad {
	[super viewDidLoad];
	if([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]){
		self.navigationController.interactivePopGestureRecognizer.delegate =self;
		self.navigationController.interactivePopGestureRecognizer.enabled = YES;
		
	}
	[self my_setupUI];
}

- (void)viewWillAppear:(BOOL)animated {
	[super viewWillAppear:animated];
	[self.view bringSubviewToFront:self.navigationView];
	NSLog(@"%@ willAppear", self.class);

}

- (void)viewDidAppear:(BOOL)animated {
	
	[super viewDidAppear:animated];
	
	
}

- (void)viewDidDisappear:(BOOL)animated {
	
	[super viewDidDisappear:animated];
	
}

- (void)dealloc {
	
	NSLog(@"%@ dealloc", self.class);
	[[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
	
	[self.view endEditing:true];
}

#pragma mark - setupUI
- (void)my_setupUI {
	
	self.view.backgroundColor = [UIColor whiteColor];
	
	[self setupNavigationView];
}

#pragma mark - privateMethod
- (void)setupNavigationView {
	
	[self.view addSubview:self.navigationView];
	//当前的导航控制器只有一个VC的时候  默认不显示返回按钮
	if (self.navigationController.viewControllers.count == 1) {
		[self.navigationView setLeftTitle:nil image:nil];
	} else {
		[self.navigationView setLeftTitle:nil image:@"nav_back"];
	}
	//右侧按钮默认不显示
	[self.navigationView setRightTitle:nil image:nil];
}

#pragma mark - publicMethod

#pragma mark - DelegateMethod
- (void)requestFinished:(__kindof YTKBaseRequest *)request {
	
	[NRWMessageHUD showMessage:@"服务繁忙, 请稍后再试" forTime:1.5 withRemindId:remindFail];
}

#pragma mark NRWNavigationViewDelegate
- (void)navigationViewLeftItemDidClick {
	
	[self.navigationController popViewControllerAnimated:YES];
}

- (void)navigationViewRightItemDidClick { }

#pragma mark - touchEventAction

#pragma mark - setter

#pragma mark - getter
- (NRWNavigationView *)navigationView {
	
	if (_navigationView == nil) {
		_navigationView = [[NRWNavigationView alloc] init];
		_navigationView.delegate = self;
	}
	return _navigationView;
}

- (CGFloat)navigationViewHeight {
	
	return SCREEN_HEIGHT() == 812? 84: 64;
}
- (void)callPhoneWithPhoneNum:(NSString *)phoneNum {
	
	NSString *str = [NSString stringWithFormat:@"tel:%@", phoneNum];
	if (@available(iOS 10.0, *)) {
		[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str] options:@{} completionHandler:^(BOOL success) {
			
		}];
	} else {
		[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
	}
	
}

@end
